package com.epam.qanda.db.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.epam.qanda.db.ConnectionManager;
import com.epam.qanda.db.dao.BaseDao;
import com.epam.qanda.db.mapping.Converter;
import com.epam.qanda.db.model.ModeratorCategoryName;

public class ModeratorCategoryNameDao implements BaseDao {

	private final String GET_MODERATOR_CATEGORIES_BY_USER_ID = "SELECT mc.user_id, mc.category_id, c.name FROM moderator_category mc JOIN category c ON mc.category_id = c.id WHERE mc.user_id=?";

	@Override
	public <T> void create(T element) {
	}

	@Override
	public <T> T read(Integer id) {
		return null;
	}

	@Override
	public void delete(Integer id) {
	}

	@Override
	public <T> void update(T element) {
	}

	public List<ModeratorCategoryName> getModeratorCategories(Integer userId) {
		List<ModeratorCategoryName> list = new ArrayList<>();
		Connection connection = ConnectionManager.getInstance().getConnection();
		try (PreparedStatement statement = connection
				.prepareStatement(GET_MODERATOR_CATEGORIES_BY_USER_ID)) {
			statement.setInt(1, userId);
			ResultSet rs = statement.executeQuery();
			while (rs.next()) {
				list.add(Converter.<ModeratorCategoryName> fromResaultSetToObject(
						rs, ModeratorCategoryName.class));
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			ConnectionManager.getInstance().release(connection);
		}
		return list;
	}
	
	
}
